<template>
  <view class="withdraw">
    <view class="top row">
      <view class="icon">
        <u-image
          src="/static/icon/wechatPay.png"
          width="50rpx"
          height="50rpx"
        ></u-image>
      </view>
      <view class="title">微信余额</view>
    </view>
	<!-- <view class="content">
	  <view class="ctitle">微信号</view>
	  <u-input
		placeholder="请输入微信号"
		border="none"
		v-model="inputValue1"
	  ></u-input>
	</view> -->
    <view class="content">
      <view class="ctitle">提现金额(每次最多可提500)</view>
      <view class="pcontet row">
        <view style="margin-right: 20rpx">¥</view>
        <u-input
          placeholder="请输入提现金额"
          border="none"
          v-model="inputValue"
        ></u-input>
      </view>
      <!-- placeholderStyle="{'font-size': '80rpx';
	  'color':' #999999';'font-weight': 'bold'}" -->
	  <view class="line space-between" v-if="userInfos.is_promoter!=1">
	    <view>待提现金额：{{nowMoney}}</view>
	    <view class="money" @click="allInput(nowMoney)">全部提现</view>
	  </view>
	  <view class="line space-between" v-if="userInfos.is_promoter==1">
	    <view class="row" @click="WithdrawalType='yue'">
			<view class="radio" :style="{background:WithdrawalType=='yue'?'	radial-gradient(circle, #2354e3, #fff);':'transparent'}"></view>
			待提现金额：{{jmoney||0}}
		</view>
		 <view class="money" @click="allInput(jmoney)">全部提现</view>
	  </view>
	  <view class="line space-between" v-if="userInfos.is_promoter==1">
		  <view class="row" @click="WithdrawalType='yj'">
		  	<view class="radio" :style="{background:WithdrawalType=='yj'?'radial-gradient(circle, #2354e3, #fff);':'transparent'}"></view>
		  	<view>佣金：{{canWithdraw}}  (最低提现金额{{minimum}}) </view>
		  </view>
	  </view>
      <view class="btn" @click="withdraw">提现</view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      // 输入充值余额
      inputValue: "",
	  // inputValue1:"",
	  canWithdraw:0,
	  minimum:0,
	  nowMoney:0,
	  userInfos:{},
	  value:false,
	  WithdrawalType:'yue',
	  jmoney:0
    };
  },
  onLoad(options) {
	  if(options.brokerage){
		  this.canWithdraw = options.brokerage;
	  }
	  if(options.now_money){
		  this.nowMoney = options.now_money;
	  }
	  if(options.jmoney){
		  this.jmoney = options.jmoney;
	  }
	  this.getMinimum();
	  this.getUserInfos();
  },
  methods: {
	  getUserInfos(){
	  	this.$api.post({
	  		url: "/ebapi/user_api/get_my_user_info",
	  		data: {},
	  		success: (res) => {
	  			console.log(res,"res 用户信息")
	  			this.userInfos = res;
	  		},
	  	})
	  },
	getMinimum(){
		this.$api.post({
		  url: "/ebapi/public_api/get_user_extract_bank",
		  success: (res) => {
			this.minimum = res.minPrice;
		  },
		})	
	},
    // 全部提现
    allInput(val) {
      this.inputValue = val>0?val:0;
    },
	withdraw(){
		// if(!this.inputValue1){
		// 	uni.showToast({
		// 		title:"请输入提现微信号！",
		// 		icon:"none"
		// 	})
		// 	return
		// }
		if(!this.inputValue){
			uni.showToast({
				title:"请输入需要提现的金额！",
				icon:"none"
			})
			return
		}
		// 代理提现
		let type = 1
		if(this.userInfos && this.userInfos.is_promoter==1){
			if(this.WithdrawalType=="yj"){
				type = 2;
				console.log(this.inputValue,this.minimum,this.canWithdraw,"this.inputValue,this.minimum，canWithdraw")
				if(this.inputValue>=this.minimum){
					console.log(Number(this.canWithdraw)<this.inputValue,"Number(this.canWithdraw)<this.inputValue");
					if(Number(this.canWithdraw)<this.inputValue){
						uni.showToast({
							title:"余额不足！",
							icon:"none"
						})
						return
					}
				}else{
					uni.showToast({
						title:"提现不能小于最低提现金额！",
						icon:"none"
					})
					return
				}
			}else{
				type  = 1;
				if(Number(this.nowMoney)<this.inputValue){
					uni.showToast({
						title:"待提现余额不足！",
						icon:"none"
					})
					return
				}
			}
		// 普通用户提现
		}else{
			if(Number(this.nowMoney)<this.inputValue){
				uni.showToast({
					title:"待提现余额不足！",
					icon:"none"
				})
				return
			}
		}
		if(this.inputValue>500){
			uni.showToast({
				title:"每次最大提现金额为500！",
				icon:"none"
			})
			return
		}
		let reqData = {
			money:this.inputValue,
			weixin:this.inputValue1,
			type:type
		}
		// if(type){
		// 	reqData.type = type
		// }
		this.$api.post({
		  url: "/ebapi/user_api/user_extract",
		  data:reqData,
		  success: (res) => {
			console.log(res,"res")
			uni.showToast({
				title:"已提交，待审核！"
			})
			setTimeout(()=>{
				uni.redirectTo({
					url:'/pages/my/balance?recordType=2'
				})
			},2000)
		  },
		})	
	}
  },
};
</script>

<style lang="scss">
page {
  padding: 0;
  background-color: #ffffff;
}

.withdraw {
  .top {
    padding: 60rpx 24rpx;

    .title {
      margin-left: 15rpx;
      font-size: 36rpx;
    }
  }

  .content {
    padding: 36rpx 24rpx;
    border-top: 24rpx solid #f5f5f5;

    .ctitle {
      font-size: 28rpx;
    }

    .pcontet {
      font-size: 80rpx;
      font-weight: bold;
      margin: 33rpx 0 20rpx;
      border-bottom: 1px solid #707070;
    }

    .line {
      margin-top: 20rpx;

      .money {
        color: #2354e3;
      }
	  .radio{
		  width: 30rpx; padding: 8rpx; border: 1rpx solid #2354e3; border-radius: 50%; height: 30rpx; margin-right: 10rpx;
	  }
    }

    .btn {
      font-size: $uni-text-size-title;
      color: #ffffff;
      margin: 260rpx auto;
      text-align: center;
      width: 463rpx;
      height: 72rpx;
      line-height: 72rpx;
      background: #2354e3;
      border-radius: 47rpx;
      opacity: 1;
    }
  }
}
</style>
